package com.opal.system.controller;

import com.opal.consts.CommonConst;
import com.opal.domain.ReturnMessageData;
import com.opal.system.entity.table.OpalPermission;
import com.opal.system.entity.table.OpalRole;
import com.opal.system.service.ManageService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/manage")
public class ManageController{
	
	@Autowired
	private ManageService manageService;


	
	@RequestMapping("/permission/addpermission")
	@ResponseBody
	public ReturnMessageData addPermission(OpalPermission permission) {
		ReturnMessageData rmd= manageService.addPermissionSercice(permission);
		return rmd;
	}

	/**
	 * 修改权限
	 * @param permission
	 * @return
	 */
	@RequestMapping("/permission/updatepermission")
	@ResponseBody
	public ReturnMessageData updatePermission(OpalPermission permission) {
		ReturnMessageData rmd= manageService.updatePermissionSercice(permission);
		return rmd;
	}
	
	/**
	 * 查询权限
	 * @return
	 */
	@RequestMapping("/permission/selectallpermission")
	@ResponseBody
	public List<OpalPermission> selectAllPermission() {
		List<OpalPermission> opalPermission= manageService.selectAllPermissionSercice();
		return opalPermission;
	}

	/**
	 * 删除权限
	 * @return
	 */
	@RequestMapping("/permission/deletePermission")
	@ResponseBody
	public ReturnMessageData deletePermission(@RequestBody OpalPermission[] opalPermissions) {
		ReturnMessageData resultMessage= manageService.deletePermissionSercice(opalPermissions);
		return resultMessage;
	}

	@RequiresRoles(CommonConst.ADMIN)
	@RequestMapping("{page}")
	public String skipPage(@PathVariable("page") String page) {
		return "permission_setting/"+page;
	}
}
